package com.getpebble.android.util;

import com.getpebble.android.common.core.trace.Trace;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class HockeyAppUtil {
    private static final String TAG = HockeyAppUtil.class.getSimpleName();

    public static String getLogcatLogs() {
        Throwable th;
        String description = "";
        BufferedReader bufferedReader = null;
        try {
            BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("logcat -v threadtime -d").getInputStream()));
            try {
                StringBuilder log = new StringBuilder();
                while (true) {
                    String line = bufferedReader2.readLine();
                    if (line == null) {
                        break;
                    }
                    log.append(line);
                    log.append(System.getProperty("line.separator"));
                }
                description = log.toString();
                if (bufferedReader2 != null) {
                    try {
                        bufferedReader2.close();
                        bufferedReader = bufferedReader2;
                    } catch (IOException e) {
                        Trace.warning(TAG, "Error closing buffered reader", e);
                        bufferedReader = bufferedReader2;
                    }
                }
            } catch (IOException e2) {
                bufferedReader = bufferedReader2;
                try {
                    Trace.warning(TAG, "Failed to get logs from logcat");
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e3) {
                            Trace.warning(TAG, "Error closing buffered reader", e3);
                        }
                    }
                    return description;
                } catch (Throwable th2) {
                    th = th2;
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e32) {
                            Trace.warning(TAG, "Error closing buffered reader", e32);
                        }
                    }
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                bufferedReader = bufferedReader2;
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
                throw th;
            }
        } catch (IOException e4) {
            Trace.warning(TAG, "Failed to get logs from logcat");
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            return description;
        }
        return description;
    }
}
